import { getToken } from '@/utils/token'
import { Route, Redirect } from 'react-router-dom'
/**
 * 步骤：
 *  1、先接收到传递过来的 path 和 component
 *  2、在里面返回一个 Route 配置
 */
function AuthRoute ({ component: Component, meta, ...args }) {
  return (
    <Route
      {...args}
      render={props => {
        const token = getToken()
        if (token) {
          document.title = meta.title || '黑马面面'

          return <Component {...props} />
        } else {
          return <Redirect to='/login' />
        }
      }}
    />
  )
}

export default AuthRoute
